<?php
ifi!perms_check('admin', 'modules'))
{
	redirect('index.php?module=error&error=auth_error');
	exit;
}

$i=0;
//generacja tablicy funkcji z plik�w na serwerze
$dir = opendir('includes/functions/');
while (($file = readdir($dir)) !== false)
{
	if($file[0]!='.' && $file!='thirdparty' && strpos($file, '-external')===false && strpos($file, '.php')!==false)
	{
		$server_functions[$i]=$file;
		$i++;
	}
}
closedir($dir);
//

//generacja tablicy funkcji z bazy
$i=0;

$db = new dbquery;
$db->query("SELECT * FROM $conf[prefix]functions WHERE function=1 or function='external' ORDER by name ASC") or $db->err(__FILE__, __LINE__);
while($f=$db->fetch_object())
{
	$database_functions[$i]=$f->name.'.php';
	$database_uninstall[$i]=$f->uninstall;
	$i++;
}
//

$func=array();
$option=array();
for($q=0;$q<count($server_functions);$q++)
{
	$i=array_search($server_functions[$q], $database_functions);
	if($i!==false) {  
		if($database_uninstall[$i]==1) {
			$func[]=$database_functions[$i];
			$option[]='uninstall';
		}
	}
	else {
		$func[]=$server_functions[$q];
		$option[]='install';
	}
}

$content='
<table align="center" width="100%" border="0" class="tabelka2">
<tr>
<td class="row_3" align="center">'.$lang['admin_functions'].'</td>
<td class="row_3" align="center">'.$lang['admin_options'].'</td>
</tr>';

//dodawanie wierszy do $contents
for($q=0;$q<count($func);$q++)
{ 
	$variable=explode('.', $func[$q]);

	$i++;
	if($i>2)
		$i=1;

	if($option[$q]=='install')
		$options='<a href="index.php?function=function_install&amp;variable='.$variable[0].'">'.$lang['admin_install'].'</a>';
	else
		$options='<a href="index.php?function=function_uninstall&amp;variable='.$variable[0].'">'.$lang['admin_uninstall'].'</a>';

	$content.='
		<tr>
		<td class="row_'.$i.'" align="center">'.$func[$q].'</td>
		<td class="row_'.$i.'" align="center">'.$options.'</td>
		</tr>';

}
//

$content.='</table>';   

$content=string_template(read_file('middle.php'), array('theme_path' => $GLOBALS['theme_path'], 'content' => $content, 'description'=>'Funkcje'));
//
?>
